/*******************************************************************
 * Filename:	BitOps.h
 * Description:	Defines a bitfield and creates the use table. 
 *				Also holds functions to manipulate metatable entries
 * 
 * Group 2:		nachOS
 * Author(s):	Jan Durakiewicz
 * 
 * Class:		CSE 325
 * Instructor:	David Duggan
 * Assignment:	Lab #5 Memory Manager
 * Assigned:	3/20/2013
 * Due:			4/2/2013
 *******************************************************************/
#ifndef BITOPS_H
#define BITOPS_H
#define USE_TABLE_SIZE 16384


typedef unsigned long bitfield_t[USE_TABLE_SIZE/(sizeof(long) * 8)];
bitfield_t useTable;

/***
 * Gets the value of the bit in the use table at the given index
 * @author Jan Durakiewicz
 * @param index which bit to read
 * @return the value of the bit at the given index
 */
short unsigned int get_use_table_at(short unsigned int index);

/***
 * Sets the bit value of the use table at the given index
 * @author Jan Durakiewicz
 * @param index wich bit to modify
 * @param value what to set that bit to (1 or 0)
 */
void set_use_table_at(short unsigned int index, short unsigned int value);

/***
 * Checks whether a given page table entry is marked valid
 * @author Jan Durakiewicz
 * @param entry pointer to entry to be analyzed
 * @return 1 if the page is valid, 0 if not
 */
short unsigned int get_page_validity(unsigned short int* entry);

/***
 * Extracts the physical page number from the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to extract from
 * @return numeric value of physucal page number
 */
short unsigned int get_page_address(short unsigned int* entry);

/***
 * Sets the physical page number for the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to set address of
 * @param address the physical page number to write to it
 */
void set_page_address(short unsigned int* entry, short unsigned int address);

/***
 * Sets the validity for the given page table entry
 * @author Jan Durakiewicz
 * @param entry pointer to page table entry to set validity of
 * @param address whether to set as valid (1) or invalid (0)
 */
void set_page_validity(short unsigned int* entry, short unsigned int isValid);

#endif

